Skip to content

London | 26-SDC-March | Zobeir Rigi | Sprint 2 | Implement an LRU cache - #207

Open
Zobeir-Rigi wants to merge 2 commits into
CodeYourFuture:mainfrom
Zobeir-Rigi:implement-lru-cache
Open

London | 26-SDC-March | Zobeir Rigi | Sprint 2 | Implement an LRU cache#207
Zobeir-Rigi wants to merge 2 commits into
CodeYourFuture:mainfrom
Zobeir-Rigi:implement-lru-cache

Conversation

@Zobeir-Rigi

Copy link
Copy Markdown
  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

I originally completed all the Sprint 2 exercises in one PR, but the validation expected separate PRs for each issue. This PR contains only the solution for the "Implement an LRU cache in Python" exercise.

Implemented an LRU cache with:

  • set
  • get
  • LRU eviction policy

All provided tests pass.

@Zobeir-Rigi Zobeir-Rigi added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Complexity The name of the module. labels Jul 6, 2026
Comment on lines +1 to +10
class Node:
def __init__(self, key, value):
self.key = key
self.value = value
self.next = None
self.previous = None


class LruCache:
def __init__(self, limit):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To better adhere to the Single-Responsibility Principle (SRP) from SOLID design principles,
it's preferable to implement the "doubly linked list" and the "LRU Cache" as separate classes, with the linked list used inside LruCache to manage ordering. In fact, you could just import the linked list which you implemented in the other exercise.

Alternatively, OrderedDict can be used directly within LruCache to maintain order.

Could you update your code using one of these approaches?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To better adhere to the Single-Responsibility Principle (SRP) from SOLID design principles, it's preferable to implement the "doubly linked list" and the "LRU Cache" as separate classes, with the linked list used inside LruCache to manage ordering. In fact, you could just import the linked list which you implemented in the other exercise.

Alternatively, OrderedDict can be used directly within LruCache to maintain order.

Could you update your code using one of these approaches?

I agree with the suggestion. Since the LinkedList implementation is in a separate branch, I couldn't import it directly here. Instead, I separated the linked-list logic into its own class and used it within LruCache to keep the responsibilities separate.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To by pass the validation bot check, you could copy the linked_list.py from the other folder to the implement_lru_cache folder, and then import the class. It would be a good practice for code reuse.

@cjyuan cjyuan added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jul 9, 2026
@cjyuan

cjyuan commented Jul 15, 2026

Copy link
Copy Markdown

Changes look good.

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. Module-Complexity The name of the module. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants